namespace SolidMvvm {
	using System;
	using System.Globalization;
	using System.Windows.Data;

	/// <summary>
	///     This converter can multiply a double value by any other double value.
	/// </summary>
	[ValueConversion(typeof(double), typeof(double))]
	public class DoubleToMultipliedDoubleConverter : IValueConverter {
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			if (value == null || parameter == null)
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must specify a value and a multiplier parameter.");
			if (!(value is double) && !(value is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string or double value.");
			if (!(parameter is double) && !(parameter is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string or double parameter.");

			var doubleValue = value is double ? (double)value : double.Parse((string)value);
			var doubleParameter = parameter is double ? (double)parameter : double.Parse((string)parameter);
			return doubleValue * doubleParameter;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			if (parameter == null)
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must specify a value and a multiplier parameter.");
			if (!(value is double) && !(value is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string or double value.");
			if (!(parameter is double) && !(parameter is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string or double parameter.");

			var doubleValue = value is double ? (double)value : double.Parse((string)value);
			var doubleParameter = parameter is double ? (double)parameter : double.Parse((string)parameter);
			return doubleValue / doubleParameter;
		}
	}
}
